home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 November / Chip Kasım 2000.iso / prog / share / 11 / setup.exe / %MAINDIR% / DEMOS / CIMAIL / INTMAIL / ctrlpan.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  2000-09-07  |  29.4 KB  |  806 lines

  1. VERSION 4.00
  2. Begin VB.Form ControlPanel 
  3.    BackColor       =   &H00FFFFFF&
  4.    BorderStyle     =   4  'Fixed ToolWindow
  5.    Caption         =   "Internet Mail"
  6.    ClientHeight    =   3585
  7.    ClientLeft      =   1020
  8.    ClientTop       =   1485
  9.    ClientWidth     =   8445
  10.    Height          =   3990
  11.    Icon            =   "CtrlPan.frx":0000
  12.    Left            =   960
  13.    LinkTopic       =   "Form1"
  14.    LockControls    =   -1  'True
  15.    MaxButton       =   0   'False
  16.    MinButton       =   0   'False
  17.    ScaleHeight     =   3585
  18.    ScaleWidth      =   8445
  19.    ShowInTaskbar   =   0   'False
  20.    Top             =   1140
  21.    Width           =   8565
  22.    Begin VB.Label lblReadMe 
  23.       BackStyle       =   0  'Transparent
  24.       Caption         =   "Common Dialog control used to work with files."
  25.       ForeColor       =   &H00800000&
  26.       Height          =   645
  27.       Index           =   3
  28.       Left            =   6060
  29.       TabIndex        =   7
  30.       Top             =   2910
  31.       Visible         =   0   'False
  32.       Width           =   2055
  33.       WordWrap        =   -1  'True
  34.    End
  35.    Begin MSComDlg.CommonDialog ComDialog 
  36.       Left            =   5475
  37.       Top             =   2895
  38.       _ExtentX        =   847
  39.       _ExtentY        =   847
  40.       _Version        =   327681
  41.       CancelError     =   -1  'True
  42.       Filter          =   "All Files (*.*)|*.*"
  43.       FilterIndex     =   1
  44.       FontSize        =   2.54052e-29
  45.    End
  46.    Begin VB.Image Exit 
  47.       Height          =   435
  48.       Left            =   4140
  49.       MouseIcon       =   "CtrlPan.frx":0442
  50.       MousePointer    =   99  'Custom
  51.       Picture         =   "CtrlPan.frx":0594
  52.       Top             =   3030
  53.       Width           =   870
  54.    End
  55.    Begin VB.Label MailProperties 
  56.       BackStyle       =   0  'Transparent
  57.       Height          =   420
  58.       Left            =   555
  59.       MouseIcon       =   "CtrlPan.frx":10A2
  60.       MousePointer    =   99  'Custom
  61.       TabIndex        =   6
  62.       Top             =   1650
  63.       Width           =   4425
  64.    End
  65.    Begin VB.Label GetMail 
  66.       BackStyle       =   0  'Transparent
  67.       Height          =   420
  68.       Left            =   555
  69.       MouseIcon       =   "CtrlPan.frx":11F4
  70.       MousePointer    =   99  'Custom
  71.       TabIndex        =   5
  72.       Top             =   975
  73.       Width           =   2895
  74.    End
  75.    Begin VB.Label SendMail 
  76.       BackStyle       =   0  'Transparent
  77.       Height          =   420
  78.       Left            =   615
  79.       MouseIcon       =   "CtrlPan.frx":1346
  80.       MousePointer    =   99  'Custom
  81.       TabIndex        =   4
  82.       Top             =   315
  83.       Width           =   3225
  84.    End
  85.    Begin VB.Line lneBorder 
  86.       BorderColor     =   &H00808080&
  87.       BorderWidth     =   3
  88.       Index           =   1
  89.       X1              =   135
  90.       X2              =   4980
  91.       Y1              =   2400
  92.       Y2              =   2400
  93.    End
  94.    Begin VB.Line lneBorder 
  95.       BorderColor     =   &H00808080&
  96.       BorderWidth     =   2
  97.       Index           =   0
  98.       X1              =   300
  99.       X2              =   300
  100.       Y1              =   90
  101.       Y2              =   2625
  102.    End
  103.    Begin VB.Image ButtonImages 
  104.       Height          =   2010
  105.       Left            =   435
  106.       Picture         =   "CtrlPan.frx":1498
  107.       Top             =   210
  108.       Width           =   4590
  109.    End
  110.    Begin VB.Image MailLogo 
  111.       Height          =   870
  112.       Left            =   570
  113.       MouseIcon       =   "CtrlPan.frx":BA12
  114.       MousePointer    =   99  'Custom
  115.       Picture         =   "CtrlPan.frx":BB64
  116.       Top             =   2595
  117.       Width           =   2895
  118.    End
  119.    Begin VB.Label lblReadMe 
  120.       AutoSize        =   -1  'True
  121.       BackStyle       =   0  'Transparent
  122.       Caption         =   "MIME control is used to encode and decode attachments."
  123.       ForeColor       =   &H00800000&
  124.       Height          =   390
  125.       Index           =   2
  126.       Left            =   6060
  127.       TabIndex        =   3
  128.       Top             =   1335
  129.       Visible         =   0   'False
  130.       Width           =   2295
  131.       WordWrap        =   -1  'True
  132.    End
  133.    Begin VB.Label lblReadMe 
  134.       BackStyle       =   0  'Transparent
  135.       Caption         =   "POP control is used to receive mail."
  136.       ForeColor       =   &H00800000&
  137.       Height          =   510
  138.       Index           =   1
  139.       Left            =   6060
  140.       TabIndex        =   2
  141.       Top             =   765
  142.       Visible         =   0   'False
  143.       Width           =   2265
  144.       WordWrap        =   -1  'True
  145.    End
  146.    Begin VB.Label lblReadMe 
  147.       BackStyle       =   0  'Transparent
  148.       Caption         =   "SMTP control is used to send mail."
  149.       ForeColor       =   &H00800000&
  150.       Height          =   510
  151.       Index           =   0
  152.       Left            =   6060
  153.       TabIndex        =   1
  154.       Top             =   195
  155.       Visible         =   0   'False
  156.       Width           =   2265
  157.       WordWrap        =   -1  'True
  158.    End
  159.    Begin CIMIMELib.CIMIME MimeControl 
  160.       Height          =   450
  161.       Left            =   5460
  162.       Top             =   1335
  163.       Width           =   480
  164.       _Version        =   65537
  165.       _ExtentX        =   847
  166.       _ExtentY        =   794
  167.       _StockProps     =   0
  168.       SourceFilename  =   ""
  169.       DestinationFilename=   "C:\$$$CIMIME.TMP"
  170.       ProgressDialogVisible=   -1  'True
  171.    End
  172.    Begin CIMAILLib.CIPOP PopControl 
  173.       Height          =   450
  174.       Left            =   5460
  175.       Top             =   735
  176.       Width           =   480
  177.       _Version        =   65536
  178.       _ExtentX        =   847
  179.       _ExtentY        =   794
  180.       _StockProps     =   0
  181.       POPServerConnectionWAV=   ""
  182.       POPServerConnectionClosedWAV=   ""
  183.       MessageReceivedWAV=   ""
  184.       STATReceivedWAV =   ""
  185.       PacketReceivedWAV=   ""
  186.       PacketSentWAV   =   ""
  187.       SocketClosedWAV =   ""
  188.       WSAErrorWAV     =   ""
  189.       LocalFileName   =   ""
  190.       HostAddress     =   ""
  191.       HostName        =   ""
  192.       MessageNumber   =   ""
  193.       Password        =   ""
  194.       UserName        =   ""
  195.    End
  196.    Begin VB.Label CrescentLabel 
  197.       AutoSize        =   -1  'True
  198.       BackStyle       =   0  'Transparent
  199.       Caption         =   "Crescent Internet ToolPak"
  200.       BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  201.          Name            =   "MS Sans Serif"
  202.          Size            =   9.75
  203.          Charset         =   0
  204.          Weight          =   700
  205.          Underline       =   0   'False
  206.          Italic          =   -1  'True
  207.          Strikethrough   =   0   'False
  208.       EndProperty
  209.       ForeColor       =   &H00000000&
  210.       Height          =   240
  211.       Left            =   5400
  212.       TabIndex        =   0
  213.       Top             =   2490
  214.       Visible         =   0   'False
  215.       Width           =   3030
  216.       WordWrap        =   -1  'True
  217.    End
  218.    Begin CIMAILLib.CISMTP SMTPControl 
  219.       Height          =   450
  220.       Left            =   5460
  221.       Top             =   165
  222.       Width           =   480
  223.       _Version        =   65536
  224.       _ExtentX        =   847
  225.       _ExtentY        =   794
  226.       _StockProps     =   0
  227.       SMTPServerConnectionWAV=   ""
  228.       SMTPServerConnectionClosedWAV=   ""
  229.       ListBoxPopulatedWAV=   ""
  230.       PacketReceivedWAV=   ""
  231.       PacketSentWAV   =   ""
  232.       SocketClosedWAV =   ""
  233.       WSAErrorWAV     =   ""
  234.       HostName        =   ""
  235.       HostAddress     =   ""
  236.       DomainName      =   ""
  237.       Sender          =   ""
  238.       Recipient       =   ""
  239.       MailList        =   ""
  240.       MessageBody     =   ""
  241.       MessageSubject  =   ""
  242.       CC              =   ""
  243.       BC              =   ""
  244.    End
  245. Attribute VB_Name = "ControlPanel"
  246. Attribute VB_Creatable = False
  247. Attribute VB_Exposed = False
  248. Option Explicit
  249. '<Contant>-----------------------------------------------
  250. Const ciMaxSendMsg                      As Integer = 10
  251. Const ciMaxReceiveMsg                   As Integer = 10
  252. '</Contant>----------------------------------------------
  253. '<Private>-----------------------------------------------
  254. Private ReceiveForms(ciMaxReceiveMsg)   As Form
  255. Private SendForms(ciMaxSendMsg)         As Form
  256. Private Attachments()                   As String
  257. Private NumAttachments                  As Integer
  258. '</Private>----------------------------------------------
  259. '<Public>------------------------------------------------
  260. Public IsAttachment         As Boolean
  261. Public CurrentSendForm      As Form
  262. '</Public>-----------------------------------------------
  263. Private Sub MimeControl_DecodingFile(FileName As String, ByVal ContentType As String, ByVal ContentEncoding As String)
  264. '-- This event fires for each MIME part in a message
  265. Dim UpBound As Integer
  266. Static AttachPath As String
  267. If Len(AttachPath) = 0 Then
  268.     AttachPath = App.Path
  269.     If right$(AttachPath, 1) <> "\" Then AttachPath = AttachPath + "\"
  270. End If
  271. '-- If we have a filename, then it is an attachment
  272. If Len(FileName) Then
  273.     UpBound = UBound(Attachments) + 1
  274.     ReDim Preserve Attachments(0 To UpBound)
  275.     FileName = AttachPath & FileName
  276.     Attachments(UpBound) = FileName
  277.     NumAttachments = UpBound
  278. '-- Otherwise, it is either the message body, or some other type
  279. '-- TEXT/PLAIN is usually the message. Save it to a file for later retrieval
  280.     If UCase$(left$(ContentType, 11)) = "TEXT/PLAIN" Then
  281.         FileName = "C:\$$BODY.TXT"
  282.         Attachments(0) = FileName
  283. '-- Treat TEXT/HTML as an attachment since this application can not display it
  284.     ElseIf UCase$(left$(ContentType, 10)) = "TEXT/HTML" Then
  285.         UpBound = UBound(Attachments) + 1
  286.         ReDim Preserve Attachments(0 To UpBound)
  287.         FileName = GetNewFilename(AttachPath, ".html")
  288.         Attachments(UpBound) = FileName
  289.         NumAttachments = UpBound
  290.     End If
  291. End If
  292. End Sub
  293. Private Function GetNewFilename(ByVal FilePath As String, ByVal FileExt As String) As String
  294. Dim strName As String
  295. Dim nCount As Integer
  296. nCount = 1
  297. strName = FilePath & "MailMessage" & nCount & FileExt
  298. strName = Dir(strName)
  299. Do While Len(strName)
  300.     nCount = nCount + 1
  301.     strName = FilePath & "MailMessage" & nCount & FileExt
  302.     strName = Dir(strName)
  303. GetNewFilename = "MailMessage" & nCount & FileExt
  304. End Function
  305. Private Sub MimeControl_DecodingFinished(ByVal Error As Integer)
  306. NumAttachments = NumAttachments - 1
  307. End Sub
  308. Private Sub MimeControl_EncodingFinished(ByVal Error As Integer)
  309.         
  310.     '---- Allow refresh of main screen
  311.     DoEvents
  312.     If (Error = 1) Then
  313.         Unload CurrentSendForm
  314.         Call Status.ShowStatus("An error occurred, unable to encode message.", vbRed, True, "Error", vbBlack)
  315.         Exit Sub
  316.     End If
  317.     Call SendMailMessage(True)
  318.     Unload CurrentSendForm
  319. End Sub
  320. Private Sub PopControl_MessageReceived()
  321.     '---- message received on the access control channel
  322.     Call Status.ShowStatus("Message received", vbBlack, , "Status", vbRed)
  323. End Sub
  324. Private Sub PopControl_PacketReceived(ByVal Packet As String)
  325.     '---- packet received on the access control channel
  326.     Call Status.ShowStatus(vbCrLf & Packet, , True, "Packet", vbBlue)
  327.         
  328. End Sub
  329. Private Sub PopControl_WSAError(ByVal error_number As Integer)
  330.     Call Status.ShowStatus("The following error occurred: " & error_number, vbRed, True, "Error", vbBlack)
  331. End Sub
  332. Private Sub Exit_Click()
  333.     Dim i As Integer
  334.     ' We don't know if we're actually connected or not.
  335.     ' If we're not, calling QUIT will take a long time,
  336.     ' because we're waiting for a server response. Shorten
  337.     ' the timeout, since we don't care at this point if or
  338.     ' how the server (if any) responds.
  339.     SMTPControl.RecvTimeout = 200
  340.     PopControl.RecvTimeout = 200
  341.     '---- quit the mail channel
  342.     SMTPControl.QUIT
  343.     PopControl.QUIT
  344.     '---- destroy all forms created by the control panel
  345.     On Error Resume Next
  346.     For i = 0 To (ciMaxReceiveMsg - 1)
  347.         Unload ReceiveForms(i)
  348.         Set ReceiveForms(i) = Nothing
  349.     Next
  350.     For i = 0 To (ciMaxSendMsg - 1)
  351.         Unload SendForms(i)
  352.         Set SendForms(i) = Nothing
  353.     Next
  354.     On Error GoTo 0
  355.     ExitProc
  356. End Sub
  357. Private Sub MailLogo_Click()
  358.     AboutBox.Show vbModal
  359. End Sub
  360. Private Sub MailProperties_Click()
  361.     Properties.Show vbModal
  362. End Sub
  363. '-------------------------------------------------
  364. '<Purpose> creates a new instance of a recieve
  365. ' form if one is available
  366. '-------------------------------------------------
  367. Private Function NewReceiveForm() As Integer
  368.     Dim i                   As Integer
  369.     Dim NumberReceiveForms  As Integer
  370.     For i = 0 To (ciMaxReceiveMsg - 1)
  371.         NumberReceiveForms = NumberReceiveForms + 1
  372.         If (ReceiveForms(i) Is Nothing) Then
  373.             Set ReceiveForms(i) = New Receive
  374.             ReceiveForms(i).FormNumber = i
  375.             NewReceiveForm = i
  376.             Exit For
  377.         End If
  378.     Next
  379.     GetMail.Enabled = (NumberReceiveForms < ciMaxReceiveMsg)
  380.     If (NumberReceiveForms = ciMaxReceiveMsg) Then
  381.         NewReceiveForm = citInvalidForm
  382.         MsgBox "Unable to receive more then " & ciMaxReceiveMsg & " messages at a time.", vbOKOnly + vbInformation, "Receive Message"
  383.     End If
  384. End Function
  385. Private Sub GetMail_Click()
  386.     Dim i               As Integer
  387.     Dim LastMessage     As Integer
  388.     Dim NumberMessages  As Integer
  389.     '---- check for new messages
  390.     NumberMessages = CheckMessages()
  391.     If (NumberMessages = 0) Then
  392.         MsgBox "You do not have any new mail.", vbOKOnly + vbInformation, "Receive Mail"
  393.     End If
  394.     For i = 1 To NumberMessages
  395.         If (i = 1) Then
  396.             LastMessage = ReceiveMessage(i)
  397.         Else
  398.             '---- offset additional messages
  399.             LastMessage = ReceiveMessage(i, LastMessage)
  400.         End If
  401.     Next
  402.     '---- close the POP control
  403.     PopControl.QUIT
  404.     DoEvents
  405. End Sub
  406. Private Sub SendMail_Click()
  407.     Call NewSendForm(True)
  408. End Sub
  409. Private Sub Form_Load()
  410.     Call GetWindowState(Me, "InternetMailMainWindow", False)
  411.     Me.Width = 5370
  412. End Sub
  413. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  414.     Set CurrentSendForm = Nothing
  415.     Call SetWindowState(Me, "InternetMailMainWindow")
  416.     ExitProc
  417. End Sub
  418. '-----------------------------------------------------
  419. '<Purpose> cleans up a receive form
  420. '-----------------------------------------------------
  421. Public Sub DestroyReceiveForm(FormNumber As Integer)
  422.     On Error Resume Next
  423.     Unload ReceiveForms(FormNumber)
  424.     Set ReceiveForms(FormNumber) = Nothing
  425.     On Error GoTo 0
  426.     GetMail.Enabled = True
  427. End Sub
  428. '-----------------------------------------------------
  429. '<Purpose> cleans up a send form
  430. '-----------------------------------------------------
  431. Public Sub DestroySendForm(FormNumber As Integer)
  432.     Unload SendForms(FormNumber)
  433.     Set SendForms(FormNumber) = Nothing
  434.     SendMail.Enabled = True
  435. End Sub
  436. Private Sub SMTPControl_PacketReceived(ByVal Packet As String)
  437.     '---- packet received on the access control channel
  438.     Call Status.ShowStatus(vbCrLf & Packet, , True, "Packet", vbBlue)
  439. End Sub
  440. '--------------------------------------------------
  441. '<Purpose> sends a mail message with an attachment
  442. '--------------------------------------------------
  443. Public Function EncodeAttachment() As Boolean
  444.     On Error GoTo BadAttachment
  445.     With MimeControl
  446.         .FireStatus = True
  447.         .SourceFilename = CurrentSendForm.AttachmentName
  448.         .DestinationFileName = "c:\$$$cimime.tmp"
  449.         .MIMEEncode
  450.     End With
  451.     EncodeAttachment = True
  452.     On Error GoTo 0
  453.     Exit Function
  454. BadAttachment:
  455.     On Error GoTo 0
  456.     EncodeAttachment = False
  457. End Function
  458. '------------------------------------------------------------
  459. '<Purpose> actually sends a message
  460. '<Note> this demo sends messages and attachments separately
  461. '------------------------------------------------------------
  462. Public Function ProcessMail() As Boolean
  463.     Dim Result    As Integer
  464.     Dim ErrorType As String
  465.     '---- hide the form while processing
  466.     CurrentSendForm.Hide
  467.     Me.Refresh
  468.     If IsAttachment Then
  469.         'If SendMailMessage(False) Then
  470.             '---- this call will start the encoding process which will then send the message
  471.             ProcessMail = EncodeAttachment()
  472.         'Else
  473.         '    ProcessMail = False
  474.         'End If
  475.     Else
  476.         ProcessMail = SendMailMessage(False)
  477.         Unload CurrentSendForm
  478.     End If
  479. End Function
  480. '---------------------------------------------------------
  481. '<Purpose> Creates a mime header and message boundary
  482. '---------------------------------------------------------
  483. Private Function AddMimeHeader(Boundary As String) As String
  484.     Dim i               As Integer
  485.     Dim Char            As Integer
  486.     Dim Header          As String
  487.     Randomize Timer
  488.     Boundary = "PART_BOUNDARY_"
  489.     For i = 1 To 10
  490.         Char = Int((26 * Rnd) + 1)
  491.         Boundary = Boundary & Chr$(Char + 64)
  492.     Next
  493.     Header = "Mime-Version: 1.0" & vbCrLf
  494.     Header = Header & "Content-Type: multipart/mixed; boundary=" & Chr$(34) & Boundary & Chr$(34) & vbCrLf
  495.     AddMimeHeader = Header & vbCrLf
  496. End Function
  497. '---------------------------------------------------------
  498. '<Purpose> actually sends a message
  499. '---------------------------------------------------------
  500. Private Function SendMailMessage(SendAttachment As Boolean) As Boolean
  501.     Dim AttachmentRead  As Boolean
  502.     Dim Result          As Integer
  503.     Dim ErrorType       As String
  504.     Dim MessageBody     As String
  505.     Dim MessageBoundary As String
  506.     Dim xmailer_old     As String
  507.     '---- store the original value of the .xmailer property
  508.     '---- it needs to be restored after the message is sent
  509.     xmailer_old = SMTPControl.XMailer
  510.     '---- general send properties
  511.     With Properties
  512.         SMTPControl.DomainName = .DomainName            '---- optional
  513.         SMTPControl.Sender = .SenderName                '---- required
  514.         SMTPControl.HostName = .SendHostName            '---- required
  515.         SMTPControl.HostAddress = .SendHostAddress      '---- required
  516.     End With
  517.     '---- message specific send properties
  518.     With CurrentSendForm
  519.         
  520.         SMTPControl.Recipient = .SendTo         '---- required
  521.         SMTPControl.CC = .CopyTo                '---- optional
  522.         SMTPControl.MessageSubject = .Subject   '---- suggested
  523.         
  524.         '---- now send message body, either text or attachment
  525.         If SendAttachment Then
  526.             AttachmentRead = ReadTempFile(MimeControl.DestinationFileName)
  527.             
  528.             If (Not AttachmentRead) Then
  529.                 MsgBox "An error occurred reading the encoded attachment.", vbOKOnly + vbExclamation, "Send Attachment"
  530.                 SendMailMessage = False
  531.                 GoTo Cleanup
  532.             End If
  533.             
  534.             SMTPControl.XMailer = SMTPControl.XMailer & vbCrLf & AddMimeHeader(MessageBoundary)
  535.             MessageBody = "--" & MessageBoundary & vbCrLf
  536.             MessageBody = MessageBody & "Content-Type: text/plain; charset=us-ascii" & vbCrLf & vbCrLf
  537.             MessageBody = MessageBody & .MessageText & vbCrLf & vbCrLf
  538.             MessageBody = MessageBody & "--" & MessageBoundary & vbCrLf
  539.             MessageBody = MessageBody & AttachmentStream & vbCrLf & vbCrLf
  540.             MessageBody = MessageBody & "--" & MessageBoundary & "--" & vbCrLf
  541.             SMTPControl.MessageBody = MessageBody
  542.         Else
  543.             SMTPControl.MessageBody = .MessageText
  544.         End If
  545.     End With
  546.     '---- connect to the server
  547.     Result = SMTPControl.ConnectToSMTPServer
  548.     If (Not (Result > 0)) Then
  549.         ErrorType = "ConnectToSMTPServer"
  550.         GoTo ShowError
  551.     End If
  552.     Call Status.ShowStatus("Connecting to mail server", vbBlack, , "Status", vbRed)
  553.         
  554.     '---- say "hello"
  555.     Result = SMTPControl.HELO
  556.     If (Result <> citSuccess) Then
  557.         ErrorType = "HELO"
  558.         GoTo ShowError
  559.     End If
  560.     Call Status.ShowStatus("Say Hello", vbBlack, , "Status", vbRed)
  561.             
  562.     '---- forward the sender to the mail system
  563.     Result = SMTPControl.MAIL
  564.     If (Result <> citSuccess) Then
  565.         ErrorType = "HELO"
  566.         GoTo ShowError
  567.     End If
  568.     Call Status.ShowStatus("Sender forwarded", vbBlack, , "Status", vbRed)
  569.     '---- forward the recipient to the mail system
  570.     Result = SMTPControl.RCPT
  571.     If (Result <> citSuccess) Then
  572.         ErrorType = "RCPT"
  573.         GoTo ShowError
  574.     End If
  575.     Call Status.ShowStatus("Recipient forwarded", vbBlack, , "Status", vbRed)
  576.     '---- send the mail message
  577.     Result = SMTPControl.Data
  578.     If (Result <> citSuccess) Then
  579.         ErrorType = "Data"
  580.         GoTo ShowError
  581.     End If
  582.             
  583.     Call Status.ShowStatus("Mail sent successfully", vbBlack, , "SendMail", vbRed)
  584.             
  585.     SendMailMessage = True
  586.     SMTPControl.XMailer = xmailer_old
  587.       
  588. Cleanup:
  589.     SMTPControl.XMailer = xmailer_old
  590.     Result = SMTPControl.QUIT
  591.     DoEvents
  592.     Exit Function
  593.       
  594. ShowError:
  595.     MsgBox "A ConnectToSMTPServer method error occurred.", vbOKOnly + vbInformation, "Send Message"
  596.     SendMailMessage = False
  597.     GoTo Cleanup
  598. End Function
  599. '-----------------------------------------------------------------
  600. '<Purpose> connects to a POP server and checks for messages
  601. '-----------------------------------------------------------------
  602. Private Function CheckMessages() As Integer
  603.     Dim Result          As Integer
  604.     Dim SocketNumber    As Integer
  605.     With Properties
  606.         
  607.         '---- validate required fields
  608.         If ((.SendHostName = "") Or (.UserName = "") Or (.Password = "")) Then
  609.             MsgBox "The Host Name, Login Name and Password fields are all required. Set them using the 'Properties' dialog.", vbOKOnly + vbInformation, "Receive Mail"
  610.             CheckMessages = -1
  611.             Exit Function
  612.         End If
  613.         
  614.         '---- set the POP control properties
  615.         PopControl.HostName = .ReceiveHostName
  616.         PopControl.HostAddress = .ReceiveHostAddress
  617.         PopControl.UserName = .UserName
  618.         PopControl.Password = .Password
  619.     End With
  620.     '---- create a connection to the server
  621.     SocketNumber = PopControl.ConnectToPOPServer
  622.     If (SocketNumber = 0) Then
  623.         MsgBox "Unable to establish a valid socket.", vbOKOnly + vbExclamation, "Receive Mail"
  624.         PopControl.QUIT
  625.         DoEvents
  626.         CheckMessages = -1
  627.         Exit Function
  628.     End If
  629.     '---- get the mail
  630.     Result = PopControl.USER
  631.     Result = PopControl.PASS
  632.     Result = PopControl.STAT
  633.     CheckMessages = PopControl.TotalMessages
  634. End Function
  635. '-------------------------------------------------------------
  636. '<Purpose> issues the retrieve command 'RETR' to actually
  637. ' get a message
  638. '-------------------------------------------------------------
  639. Private Function ReceiveMessage(MessageNumber As Integer, Optional LastMessage As Variant) As Integer
  640.     Dim Offset              As Boolean
  641.     Dim CharPos             As Integer
  642.     Dim FormNumber          As Integer
  643.     Dim OffsetLeft          As Integer
  644.     Dim OffsetTop           As Integer
  645.     Dim Result              As Integer
  646.     Dim Body                As String
  647.     Dim DestinationFileName As String
  648.     Dim i                   As Integer
  649.     '---- retrieve the message
  650.     PopControl.MessageNumber = MessageNumber
  651.     PopControl.LocalFileName = "c:\$$Mail.tmp"
  652.     Result = PopControl.RETR
  653.     If (Result <> citSuccess) Then
  654.         MsgBox "Unable to retrieve message number " & MessageNumber, vbOKOnly + vbInformation, "Receive Message"
  655.         ReceiveMessage = citInvalidForm
  656.         Exit Function
  657.     End If
  658.     '---- working with objects can generate errors
  659.     On Error GoTo BadForm
  660.     '---- create a new instance of a receive form
  661.     FormNumber = NewReceiveForm()
  662.     If (FormNumber <> citInvalidForm) Then
  663.         '---- calculate offset, if any
  664.         If (Not IsMissing(LastMessage)) Then
  665.             OffsetLeft = ReceiveForms(LastMessage).left + citFormOffset
  666.             OffsetTop = ReceiveForms(LastMessage).Top + citFormOffset
  667.             Offset = True
  668.         End If
  669.         
  670.         '---- populate and show the form
  671.         With ReceiveForms(FormNumber)
  672.             .Caption = PopControl.MessageSubject
  673.             .MessageSubject = PopControl.MessageSubject
  674.             .MessageDate = PopControl.MessageDate
  675.             .MessageHeader = PopControl.MessageHeader
  676.             
  677.             '---- may have extra CrLf at begginning !!
  678.             Body = PopControl.MessageBody
  679.             If (left(Body, 2) = vbCrLf) Then Body = Mid(Body, 3)
  680.             
  681.             '---- check for attachment
  682.             'IsAttachment = CheckForAttachment(PopControl.LocalFileName, DestinationFileName, MessageNumber)
  683.             'If (Not IsAttachment) Then
  684.             '    .MessageBody = Body
  685.             'Else
  686.                 ReDim Attachments(0 To 0)
  687.                 
  688.                 '---- MIME attachment
  689.                 On Error GoTo CannotDecode
  690.                 With MimeControl
  691.                     .SourceFilename = PopControl.LocalFileName
  692.                     .DestinationFileName = DestinationFileName
  693.                     NumAttachments = 0
  694.                     Result = .MIMEDecode
  695.                 End With
  696.                 If Result Then
  697.                     Do
  698.                         DoEvents
  699.                     Loop While NumAttachments >= 0
  700.                     .MessageBody = ExtractMessageBody(Attachments(0))
  701.                     .MessageBody = .MessageBody & vbCrLf & "Attachments:" & vbCrLf
  702.                     For i = 1 To UBound(Attachments)
  703.                         .MessageBody = .MessageBody & Attachments(i) & vbCrLf
  704.                     Next
  705.                 Else
  706.                     .MessageBody = Body
  707.                 End If
  708.                 On Error GoTo 0
  709.             'End If
  710.             
  711.             .ShowMessage
  712.             
  713.             '---- set offset
  714.             If Offset Then
  715.                 Call .ShowOffset(OffsetLeft, OffsetTop)
  716.             End If
  717.             
  718.             .Show
  719.         End With
  720.     End If
  721.     ReceiveMessage = FormNumber
  722.     On Error GoTo 0
  723.     Exit Function
  724. BadForm:
  725.     ReceiveMessage = citInvalidForm
  726.     On Error GoTo 0
  727.     Exit Function
  728. CannotDecode:
  729.     ReceiveMessage = citInvalidForm
  730.     On Error GoTo 0
  731. End Function
  732. '--------------------------------------------------------
  733. ' <Purpose> reply to a previously received mail message
  734. '--------------------------------------------------------
  735. Public Function ReplyToMessage(ThisForm As Form)
  736.     Dim FormNumber  As Integer
  737.     '---- create new form
  738.     FormNumber = NewSendForm(False)
  739.     '---- now show the form
  740.     With SendForms(FormNumber)
  741.         .SendTo = ThisForm.MessageFrom
  742.         .Subject = "Reply to: " & ThisForm.MessageSubject
  743.         .MessageText = "> In reply to your subject message:" & vbCrLf
  744.         .Show
  745.     End With
  746. End Function
  747. '--------------------------------------------------------
  748. ' <Purpose> select a file as an attachment
  749. '--------------------------------------------------------
  750. Public Function SelectFile(DefaultExt As String, DialogTitle As String) As String
  751.     On Error GoTo UserCancelled
  752.     With ComDialog
  753.         .FileName = ""
  754.         .DefaultExt = DefaultExt
  755.         .DialogTitle = DialogTitle
  756.         .Flags = cdlOFNHideReadOnly Or cdlOFNFileMustExist Or cdlOFNPathMustExist Or cdlOFNShareAware
  757.         ComDialog.Action = 1
  758.         SelectFile = .FileName
  759.     End With
  760.     On Error GoTo 0
  761.     Exit Function
  762. UserCancelled:
  763.     SelectFile = ""
  764.     On Error GoTo 0
  765. End Function
  766. '-------------------------------------------------
  767. '<Purpose> creates a new instance of a send
  768. ' form if one is available
  769. '-------------------------------------------------
  770. Private Function NewSendForm(ShowForm As Boolean) As Integer
  771.     Dim i               As Integer
  772.     Dim NumberSendForms As Integer
  773.     Dim OffsetLeft      As Integer
  774.     Dim OffsetTop       As Integer
  775.     Static FirstLeft    As Integer
  776.     Static FirstTop     As Integer
  777.     For i = 0 To (ciMaxSendMsg - 1)
  778.         NumberSendForms = NumberSendForms + 1
  779.         If (SendForms(i) Is Nothing) Then
  780.             NewSendForm = i
  781.             Set SendForms(i) = New Send
  782.             With SendForms(i)
  783.                 .FormNumber = i
  784.                 .Caption = "Send Mail (#" & i + 1 & ")"
  785.                 
  786.                 '---- calculate and show offsets
  787.                 If (i > 0) Then
  788.                     OffsetLeft = FirstLeft + (i * citFormOffset)
  789.                     OffsetTop = FirstTop + (i * citFormOffset)
  790.                     Call .ShowOffset(OffsetLeft, OffsetTop)
  791.                 End If
  792.                 
  793.                 If ShowForm Then .Show
  794.                 
  795.                 '---- cache the first left and top to offset new forms
  796.                 If (i = 0) Then
  797.                     FirstLeft = SendForms(0).left
  798.                     FirstTop = SendForms(0).Top
  799.                 End If
  800.             End With
  801.             Exit For
  802.         End If
  803.     Next
  804.     SendMail.Enabled = (NumberSendForms < ciMaxSendMsg)
  805. End Function
  806.